package com.jar.exercise.设计模式.visitor模式;

import com.jar.exercise.设计模式.visitor模式.user.Student;
import com.jar.exercise.设计模式.visitor模式.user.Teacher;
import com.jar.exercise.设计模式.visitor模式.user.User;
import com.jar.exercise.设计模式.visitor模式.visitor.Parent;
import com.jar.exercise.设计模式.visitor模式.visitor.Principal;
import com.jar.exercise.设计模式.visitor模式.visitor.Visitor;

import java.util.ArrayList;
import java.util.List;

/**
 * 基本原理：在被访问者的类里面加入对外提供接待访问者的方法
 */
public class DataView {
    final List<User> users = new ArrayList<>();
    public DataView() {
        users.add(new Student("张三","一班","学生"));
        users.add(new Teacher("王老师","一班","老师"));

    }

    public void show(Visitor visitor) {
        for (User user : users) {
            user.accept(visitor);
        }
    }

    public static void main(String[] args) {
        DataView dataView = new DataView();
        Visitor parent = new Parent();
        Visitor principal = new Principal();
        dataView.show(parent);
        dataView.show(principal);
    }
}
